//
// Copyright (c) 2024 BPer
//
#ifndef __BPerVideoEncoderHandle__
#define __BPerVideoEncoderHandle__
#include <bperutil/sys/BPerThread2.h>
#include <bperutil/buffer/BPerVideoEncoderBuffer.h>
#include <bperutil/buffer/BPerVideoBuffer.h>
#include <bperencoder/BPerVideoEncoder.h>

#include <vector>



using namespace std;
class BPerVideoEncoderHandle:public BPerThread,public BPerEncoderCallback
{
public:
	BPerVideoEncoderHandle(BPerContext* pcontext,BPerVideoInfo* pvideoInfo);
	~BPerVideoEncoderHandle(void);

private:
	int32_t m_isInit;

public:
	int32_t m_isStart;
	int32_t m_uid;
	void init();
	void stop();
	void setOutVideoBuffer(BPerVideoEncoderBuffer * pvl);
	void setInVideoBuffer(BPerVideoBuffer *pvl);


	void setVideoMetaData(BPerVideoMeta *pvmd);
	void sendMsgToEncoder(BPerRequestType request);
	void onVideoData(BPerFrame* pframe);
	void onAudioData(BPerFrame* pframe);
protected:
	void run();
	void stopLoop();
	void startLoop();
	void saveFile(char *fileName, uint8_t *pBuffer, long BufferLen);

private:
	BPerContext* m_context;
	BPerVideoBuffer *m_in_videoBuffer;
	BPerVideoEncoderBuffer *m_out_videoBuffer;
	BPerVideoMeta *m_vmd;
	int32_t m_isConvert;
	BPerVideoInfo *m_videoInfo;
	BPerVideoEncInfo *m_encInfo;
	int32_t m_sendMsgToEncoder;
	BPerRtcEncoderMessage m_request;

};
#endif
